package com.app.commands 
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.app.business.LoginDelegate;
	import com.app.control.LoginEvent;
	import com.app.model.ModelLocator;
	import com.app.vo.VO;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;	
	public class LoginCommand implements ICommand, IResponder
	{
		private var model : ModelLocator = ModelLocator.getInstance();
	   
		public function execute( event : CairngormEvent ) : void
		{
			model.login.isPending = true;
			
			var delegate : LoginDelegate = new LoginDelegate( this );   
			var loginEvent : LoginEvent = LoginEvent( event );  
			delegate.login( loginEvent.loginVO );	      
		}
		   
		public function result( data : Object ) : void
		{			
			model.login.loginDate = new Date();
			model.login.loginVO = VO( data );
			model.login.isPending = false;
			if(model.login.loginVO.hakAkses=='2'){
			     model.workflowState = ModelLocator.VIEWING_HOME_DOSEN;
			     model.workflowStateDsn=1;
		}else if(model.login.loginVO.hakAkses=='3'){
			     model.workflowState = ModelLocator.VIEWING_HOME_MAHASISWA;
			     model.workflowStateMhs=1;
		}
		}
				
		public function fault( info : Object  ) : void
		{
			// Alert.show(
			Alert.show( "Your username or password was wrong, please try again.","Alert");
			model.login.isPending = false;
		}
	}
}